package com.lwq.util;

import java.util.Arrays;
import java.util.List;

public class FormulaUtil {
	private static List<String> GrammarChars = Arrays.asList( "public", "protected", "private", "void", "int", "float", "long",
			"boolean", "bool", "double", "static", "final", "byte", "char", "enum", "native" );
	
	public static String getParamName(String formula){
		String[] strs = null;
		if(formula != null){
			strs = formula.split(" ");
			for(String item:strs){
				item.trim();
				if(item.matches("[\\w]+")){
					if(!GrammarChars.contains(item)){
						return item;
					}
				}
			}
		}
		return null;
	}
	
	public static String getMothedName(String formula){
		String[] strs = null;
		String explanation = null;
		if(formula != null){
			explanation = formula.substring(0,formula.indexOf("(",0));
			if(explanation != null){
				explanation.trim();
				strs = explanation.split(" ");
				for(String item:strs){
					item.trim();
					if(item.matches("[\\w]+")){
						if(!GrammarChars.contains(item)){
							return item;
						}
					}
				}
			}
		}
		return null;
	}
}
